std::unique_ptr
From Cppreference
| C++ Standard Library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Utilities library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dynamic memory management | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::unique_ptr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Template:cpp/memory/unique ptr/sidebar content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Defined in header <memory>
|
||
| template<
class T, |
(C++11 feature) | |
std::unique_ptr is a smart pointer that retains sole ownership of an object through a pointer. The unique_ptr can not be copied, thus it is guaranteed to be the only unique_ptr referring to that object. When the unique_ptr is destroyed, it disposes of the object through its deleter.
Contents |
[edit] Member types
| Member type | Definition | ||
| pointer | std::remove_reference<D>::type::pointer if that type exists, otherwise T*
|
||
| element_type | T | ||
| deleter_type | Deleter | ||
[edit] Member functions
Member functions | ||
|
constructs new unique_ptr (public member function) |
|
|
destructs the managed object if such is present (public member function) |
|
|
assigns the unique_ptr (public member function) |
|
Modifiers | ||
|
returns a pointer to the managed object and releases the ownership (public member function) |
|
|
replaces the managed object (public member function) |
|
|
swaps the managed objects (public member function) |
|
Observers | ||
|
returns a pointer to the managed object (public member function) |
|
|
returns the deleter that is used for destruction of the managed object (public member function) |
|
|
dereferences pointer to the managed object (public member function) |
|
|
checks if there is associated managed object (public member function) |
|
[edit] Non-member functions
|
specializes the std::swap() algorithm (function template) |
||
| This section is incomplete |